﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.DataVisualization.Charting;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Drawing;


public partial class Property_Info_Trends : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Formula f = new Formula(Master.PropertyID);
        GraphPreviousTrends();
        GraphFutureTrends();

        //Label1.Text = "71000";
        Label2.Text = "**72000";
        Label3.Text = "**73000";
        Label4.Text = "**76000";
        Label5.Text = "**";
        Label6.Text = "**";
        Label7.Text = "**";
        Label8.Text = "**";
        Label9.Visible = false;
        Zestimate zest = new Zestimate();
        ZillowLabel.Text = "**$" + zest.getZestimate("153 South Monroe Ave, Columbus, OH");
        CyberHomesEstimate cyest = new CyberHomesEstimate();
        CHLabel.Text = "**$" + cyest.GetCHestimate("153 South Monroe Ave, Columbus, OH");

        string estimate = f.GetRegularEstimate();
        //string foreclosedEstimate = f.GetDistressedEstimate();
        Label1.Text = estimate;
    }

    private void GraphPreviousTrends()
    {
        Series series1 = new Series("Line");
        series1.ChartType = SeriesChartType.Line;
        series1.BorderWidth = 3;
        series1.ShadowOffset = 2;

        //SQL query
        string connectionString = ConfigurationManager.AppSettings.Get("strConn");
        //try
        //{
            SqlConnection connection = new SqlConnection(connectionString);
            string commandText = "GIS_Get_Property_Transfers";
            SqlCommand command = new SqlCommand(commandText, connection);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.AddWithValue("@property_id", Master.PropertyID); 
            connection.Open();
            SqlDataReader dataReader = command.ExecuteReader();
            series1.Points.DataBindXY(dataReader, "Transfer_Year", dataReader, "Sale_Price");
            connection.Close();
        series1.IsValueShownAsLabel = true;

        // Add series into the chart's series collection
        Chart1.Series.Add(series1);
        Chart1.Titles.Add("Previous values of the property");
        Chart1.ChartAreas[0].BackColor = Color.Transparent;
        Chart1.BackGradientStyle = GradientStyle.HorizontalCenter;
        Chart1.BackColor = ColorTranslator.FromHtml("#b8b9b8");
        Chart1.BackSecondaryColor = ColorTranslator.FromHtml("#828282");
        
    }

    private void GraphFutureTrends()
    {
        Series series2 = new Series("Line");
        series2.ChartType = SeriesChartType.Line;
        series2.BorderWidth = 3;
        series2.ShadowOffset = 2;

        // Populate new series with data
        series2.Points.AddXY(2009, 71000);
        series2.Points.AddXY(2010, 75000);
        series2.Points.AddXY(2011, 80000);
        series2.Points.AddXY(2012, 83000);
        series2.Points.AddXY(2013, 79000);
        series2.Points.AddXY(2014, 81000);
        series2.Points.AddXY(2015, 90000);
        series2.Points.AddXY(2016, 92000);
        series2.IsValueShownAsLabel = true;

        // Add series into the chart's series collection
        Chart2.Series.Add(series2);
        Chart2.Titles.Add("Estimated future value of the property");
        Chart2.ChartAreas[0].BackColor = Color.Transparent;
        Chart2.BackGradientStyle = GradientStyle.HorizontalCenter;
        Chart2.BackColor = ColorTranslator.FromHtml("#b8b9b8");
        Chart2.BackSecondaryColor = ColorTranslator.FromHtml("#828282");
    }
    protected void ASPxButton1_Click(object sender, EventArgs e)
    {
        //try
        //{
            int mortgage = 0;
            string mtgg = ASPxTextBox1.Text;
            if (mtgg != null && mtgg != "")
            {
                mortgage = Int32.Parse(mtgg);
            }

            int monthlyCost = 0;
            string mcost = ASPxTextBox2.Text;
            if (mcost != null && mcost != "")
            {
                monthlyCost = Int32.Parse(mcost);
            }

            //Label1.Text = "71000";
            Label2.Text = "**72000";
            Label3.Text = "**73000";
            Label4.Text = "**76000";
            Label5.Text = "**" + (Int32.Parse("71000") - mortgage - monthlyCost * 0).ToString();
            Label6.Text = "**" + (Int32.Parse("72000") - mortgage - monthlyCost * 3).ToString();
            Label7.Text = "**" + (Int32.Parse("73000") - mortgage - monthlyCost * 6).ToString();
            Label8.Text = "**" + (Int32.Parse("76000") - mortgage - monthlyCost * 12).ToString();
        /*}
        catch
        {
            Label9.Visible = true;
        }*/
    }
}
